package in.muton.edushare.auth.api;

import java.io.Serializable;

public class SettingsParser implements Serializable{

	public SettingsParser(String settings) {
		this.settings = settings;
	}

	public String getString() {
		return settings;
	}

	public String getSetting(String settingName) {
		int start = settings.indexOf(settingName);
		if(start == -1)
			return "";
		int end = settings.indexOf(";", start + settingName.length());
		start += settingName.length()+1;
		if(start > end)
			return "";
		return settings.substring(start, end);
	}

	public String setSetting(String settingName, String settingValue) {
		int start = settings.indexOf(settingName);
		if(start == -1)
			return addSetting(settingName, settingValue);
		int end = settings.indexOf(";", start + settingName.length());
		String newString = settings.substring(0, start)
				+ settings.substring(end + 1, settings.length());
		newString += settingName +":" + settingValue + ";";
		settings = newString;
		return newString;
	}
	
	private String addSetting(String settingName, String settingValue){
		settings += settingName + ":" + settingValue + ";";
		return settings;
	}

	private String settings;
}
